<?php
/***************************************************************************
****************   Bordeux.NET Project             *************************
****************   File name :   receiver.php      *************************
****************   Start     :   22.05.2007 r.     *************************
****************   License   :   LGPL              *************************
****************   Version   :   1.0               *************************
****************   Authors   :   XVweb team        *************************
*************************XVweb Team*****************************************
				Krzyszof Bednarczyk, meybe you
/////////////////////////////////////////////////////////////////////////////
 Klasa XVweb jest na licencji LGPL v3.0 ( GNU LESSER GENERAL PUBLIC LICENSE)
****************http://www.gnu.org/licenses/lgpl-3.0.txt********************
		Pełna dokumentacja znajduje się na stronie domowej projektu: 
*********************http://www.bordeux.NET/Xvweb***************************
***************************************************************************/
header("Cache-Control: no-cache, must-revalidate");
if(!isset($XVwebEngine)){
	header("location: http://".$_SERVER['HTTP_HOST']."/");
	exit();
}
$soap_url = $URLS['Script'].'api/';
$class_name = strtolower($XVwebEngine->GetFromURL($PathInfo, 2));
$class_mode = strtolower($XVwebEngine->GetFromURL($PathInfo, 3));

if(empty($class_name)){
	header("location: ".$URLS['Script'].'api/xvweb/');
	exit;
}
$class_name = strtolower(str_replace(array("." , "/", "\\"),'',$class_name));
$class_file = (ROOT_DIR.'apis/'.$class_name.'.api.class.php');

if(!file_exists($class_file)){
	exit("api nie istnieje");
}
	
if($class_mode == "soap"){
	$soapClass = "api_".$class_name;
	session_name ($soapClass);
	include_once($class_file);
	$server = new SoapServer(null, array('uri' => $soap_url.$class_name.'/soap/', 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL));
	$server->setClass($soapClass);
	$server->setPersistence(SOAP_PERSISTENCE_SESSION);
	$server->handle();
	exit;
}elseif($class_mode == "wsdl"){
	include_once($class_file);
	include_once($XVwebDir.'libraries/apis_servers/WSDL_Gen.php');
	$wsdlgen = new WSDL_Gen("api_".$class_name, $soap_url.$class_name.'/soap/', "api_".$class_name);
		
	header("Content-Type: text/xml");
	echo $wsdlgen->toXML();
	exit;
}elseif($class_mode == "json"){
	header("Content-Type: text/xml");
	echo $wsdlgen->toXML();
	exit;
}
	

include_once($class_file);
include_once($XVwebDir.'libraries/apis_servers/WSDL_Gen.php');
$wsdlgen = new WSDL_Gen("api_".$class_name, $soap_url.$class_name.'/soap/', "api_".$class_name);
	
echo "<table>";
foreach ($wsdlgen->operations as $operName => $oper) {
	echo "<tr>";
	echo "<td>";
	
	// return value
	$retMsg = $oper['output'];
	$retString = 'void';
	if (count($retMsg) > 0) {
		$retString =$retMsg[0]['type']; 
	}
	
	// input parameters
	$paramMsg = $oper['input'];
	$paramString = '';
	if (count($paramMsg) > 0) {
		foreach ($paramMsg as $paramEntry) {
			if (strlen($paramString) > 0) {
				$paramString .= ', ';
			}
			$paramString .= $paramEntry['type'].' $'.$paramEntry['name'];
		}
	}
	echo $retString." ".$operName."(".$paramString.")";
	echo "</td>";
	echo "<td style='white-space: pre;'>".$oper['documentation']."</td>";
	
	echo "</tr>";
}
echo "</table>";


?>